home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MIDISTUF.ZIP / dec.cpp next >
Encoding:
C/C++ Source or Header  |  1995-01-01  |  1.8 KB  |  65 lines

  1. /*  file  dec.cpp
  2.  
  3. by  Dustin Caldwell    (dustin@gse.utah.edu)
  4.  
  5. */
  6.  
  7.  
  8. #include <dos.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. void helpdoc();
  13.  
  14. main()
  15. {
  16.         FILE *fp;
  17.  
  18.         unsigned char ch, c;
  19.  
  20.         if((fp=fopen(_argv[1], "rb"))==NULL)            /* open file to read */
  21.         {
  22.                 printf("cannot open file %s\n",_argv[1]);
  23.                 helpdoc();
  24.                 exit(-1);
  25.         }
  26.  
  27.         c=0;
  28.         ch=fgetc(fp);
  29.  
  30.         while(!feof(fp))                        /* loop for whole file */
  31.         {
  32.                 printf("%u\t", ch);             /* print every byte's decimal equiv. */
  33.                 c++;
  34.                 if(c>8)                                 /* print 8 numbers to a line */
  35.                 {
  36.                         c=0;
  37.                         printf("\n");
  38.                 }
  39.  
  40.                 ch=fgetc(fp);
  41.         }
  42.  
  43.         fclose(fp);                     /* close up */
  44. }
  45.  
  46. void helpdoc()                  /* print help message */
  47. {
  48.         printf("\n   Binary File Decoder\n\n");
  49.  
  50.         printf("\n Syntax:  dec binary_file_name\n\n");
  51.  
  52.         printf("by Dustin Caldwell  (dustin@gse.utah.edu)\n\n");
  53.         printf("This is a filter program that reads a binary file\n");
  54.         printf("and prints the decimal equivalent of each byte\n");
  55.         printf("tab-separated. This is mostly useful when piped \n");
  56.         printf("into another file to be edited manually.  eg:\n\n");
  57.         printf("c:\>dec sonata3.mid > son3.txt\n\n");
  58.         printf("This will create a file called son3.txt which can\n");
  59.         printf("be edited with any ascii editor. \n\n");
  60.         printf("(rec.exe may also be useful, as it reencodes the \n");
  61.         printf("ascii text file).\n\n");
  62.         printf("Have Fun!!\n");
  63. }
  64.  
  65.